
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QDragEnterEvent>
#include <QFileInfoList>
#include <QMainWindow>
#include <QMessageBox>
#include <QProcess>
#include <QWidget>

QT_BEGIN_NAMESPACE

QT_END_NAMESPACE
namespace Ui {
    class MainWindow;
}
class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private:
    void connectProcess(QProcess *process);
    QProcess *createConnectProcess();
    void runConnectProcessCommand(const QString &command);
    void runEnableConnectProcessCommand(const QString &command, QWidget *widget);
    void runWaitConnectProcessCommand(const QString &command);

    bool isChoosedImgDir();
    bool isChoosedBootImg();
    bool isChoosedUpdateZip();
    bool isChoosedBootLoaderImg();
    bool isChoosedRadioImg();
    bool isChoosedManualUpdateImgDir();

    bool fileInfoListHasName(const QFileInfoList &list, QString filename);
    QMessageBox *createEraseWarringMessage(const QString &partition);
    QMessageBox *createFlashWarringMessage(const QString &partition);
    QMessageBox *createFlashSystemWarringMessage();
    QMessageBox *createUpdateWarringMessage();
    QMessageBox *createTransferFilesWarringMessage(const QStringList &fileNames);

private slots:
    // adb
    void on_adb_devices_clicked();
    void on_adb_reboot_clicked();
    void on_adb_reboot_bootloader_clicked();
    void on_adb_root_clicked();
    void on_adb_shell_bootctl_current_slot_clicked();
    void on_adb_bootctl_next_a_clicked();
    void on_adb_bootctl_next_b_clicked();
    void on_adb_kill_server_clicked();

    // fastboot
    void on_fast_devices_clicked();
    void on_fast_reboot_clicked();
    void on_fast_reboot_bootloader_clicked();
    void on_fast_set_a_clicked();
    void on_fast_set_b_clicked();
    void on_fast_getvar_all_clicked();
    void on_fast_getvar_some_clicked();
    void on_fast_getvar_current_slot_clicked();

    // flash
    void on_lineEdit_textChanged(const QString &arg1);
    void on_chooseDir_clicked();
    void on_do_fast_flashall_clicked();

    // erase
    void on_do_fast_erase_userdata_clicked();
    void on_do_fast_erase_boot_clicked();
    void on_do_fast_erase_system_clicked();

    // boot.img
    void on_lineEditBoot_textChanged(const QString &arg1);
    void on_chooseBootFile_clicked();
    void on_do_fast_flash_recovery_clicked();
    void on_do_fast_flash_boot_clicked();
    void on_do_fast_boot_clicked();

    // logger panel
    void on_textEdit_textChanged();

    // update zip
    void on_lineEditUpdateZip_textChanged(const QString &arg1);
    void on_chooseUpdateZip_clicked();
    void on_do_fast_update_zip_clicked();

    void on_lineEditBootLoader_textChanged(const QString &arg1);
    void on_chooseBootLoader_clicked();
    void on_do_fast_flash_bootloader_clicked();

    void on_lineEditRadioImg_textChanged(const QString &arg1);
    void on_chooseRadioImg_clicked();
    void on_do_fast_flash_radio_clicked();

    void on_lineEdit4ImagesDir_textChanged(const QString &arg1);
    void on_manual_update_fast_flash_clicked();
    void on_manual_update_chooseDir_clicked();
    void on_manual_update_fast_erase_clicked();
    void on_manual_updata_listwidget_currentTextChanged(const QString &currentText);

    void on_transfer_data_clicked();

    void on_transfer_system_bin_clicked();

    void on_transfer_sdcard_clicked();

    void on_manual_updata_listwidget_itemSelectionChanged();

private:
    Ui::MainWindow *ui;

    void dropTrasferFiles(QDropEvent *event);
    void dropUpdateFolder(QDropEvent *event);


    // QWidget interface
protected:
    void dragEnterEvent(QDragEnterEvent *event) override;
    void dragMoveEvent(QDragMoveEvent *event) override;
    void dropEvent(QDropEvent *event) override;
private slots:
    void on_other_fastboot_reboot_fastbootd_clicked();
};

#endif // MAINWINDOW_H

